//
//  UINavigationController+PopPush.m
//  ZoeHealthPublic
//
//  Created by 徐秀滨 on 2018/11/20.
//  Copyright © 2018 Zoenet (Xiamen) Health Co.,Ltd. All rights reserved.
//

#import "UINavigationController+PopPush.h"

@implementation UINavigationController (PopPush)

- (nullable UIViewController *)popViewControllerAnimated:(BOOL)animated block:(void(^)(void))block {
    self.delegate = self;
    self.block = block;
    return [self popViewControllerAnimated:animated];
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if(self.block){
        self.block();
        [self setBlock:nil];
    }
}

- (void)setBlock:(void(^)(void))block {
    objc_setAssociatedObject(self, @selector(block), block, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

- (void (^)(void))block {
    return objc_getAssociatedObject(self, @selector(block));
}

@end
